package massim.jason.acao;

import jason.asSemantics.DefaultInternalAction;
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.NumberTerm;
import jason.asSyntax.NumberTermImpl;
import jason.asSyntax.Term;

public class FindPos extends DefaultInternalAction {
	private static final long serialVersionUID = -5510850919163477646L;

	@Override
	public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
		Term x = args[0];
		Term y = args[1];
		Term cX = args[2];
		Term cY = args[3];
		Term newX = args[5];
		Term newY = args[6];
		
		// Unfold terms (obtem os valores primitivos dos termos AgentSpeak)
		double vx = ((NumberTerm)x).solve();
		double vy = ((NumberTerm)y).solve();
		double vCx = ((NumberTerm)cX).solve();
		double vCy = ((NumberTerm)cY).solve();
		
		// INÍCIO do código de Pathfinding
		// Simplesmente ir na direção dela!
		double vNewX = vCx;
		double vNewY = vCy;
		// FIM do código de Pathfinding
		
		// Update output terms
		un.unifies(newX, new NumberTermImpl(vNewX));
		un.unifies(newY, new NumberTermImpl(vNewY));
		
		// everything ok, so returns true
		return true;
	}
}
